from django.db import models
# 导入时间域
from django.utils import timezone


# 基类
class Base(models.Model):
    # 创建时间
    create_time = models.DateTimeField(default=timezone.now, null=True)

    class Meta:
        abstract = True


# 用户表
class User(Base):
    # 用户名
    username = models.CharField(max_length=200)
    # 密码
    password = models.CharField(max_length=200)
    # 头像
    img = models.CharField(max_length=200, null=True)
    # 用户类别 (0普通用户，1超级管理员，2网站编辑)
    type = models.IntegerField(default=0)
    # 手机号
    phone = models.CharField(null=True, max_length=11)
    # 个人主页
    num = models.IntegerField(default=0, null=True)

    class Meta:
        db_table = 'user'


# 整形是mysql里面最快的数据类型

# 轮播图表
class Carousel(Base):
    name = models.CharField(max_length=200)
    src = models.CharField(max_length=200)
    img = models.CharField(max_length=200)

    class Meta:
        db_table = 'carousel'

class Category(Base):
    name = models.CharField(max_length=200)

    class Meta:
        db_table = 'category'

# 商品表
class Goods(Base):
    name = models.CharField(max_length=200, null=True)
    desc = models.CharField(max_length=200, null=True)
    img = models.CharField(max_length=200, null=True)
    video = models.CharField(max_length=200, null=True)
    price = models.IntegerField(null=True)
    params = models.CharField(max_length=400, null=True)
    flow = models.IntegerField(default=0, null=True)
    cid = models.ForeignKey(Category, null=True, on_delete=models.CASCADE)

    class Meta:
        db_table = 'goods'


# 商品评论表
class Comment(Base):
    uid = models.IntegerField()
    content = models.CharField(max_length=400)
    gid=models.IntegerField()
    class Meta:
        db_table='comment'